package com.hspedu.static_;

/**
 * @Author Stringzhua
 * @Date 2024/3/4 20:55
 * description:查看bug,修改后看输出什么?
 */
public class StaticExercise02 {
    public static void main(String[] args) {
        System.out.println("Number of total is = " + Person.getTotalPerson());//0
        Person p1 = new Person();
        System.out.println("Number of total is = " + Person.getTotalPerson());//1
    }
}

class Person {
    private int id;
    private static int total = 0;

    public static int getTotalPerson() {
//        id++;//java: 无法从静态上下文中引用非静态 变量 id
        return total;
    }

    public Person() {
        //构造器是非静态方法,可以访问所有的属性
        total++;//total=1
        id = total;//id=1
    }
}